/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief HubCtrl protocol handler module - header.
 * \author Antti Maula <antti.maula@tkk.fi>
 *
 */
#ifndef _HUBCTRL_H_
#define _HUBCTRL_H_

#include "hubctrlHdr.h"
#include "../protocol.h"

// Functions return values
#define HUBCTRL_ERROR                            -1
#define HUBCTRL_OK                               0


//***************************************************************************

/** Structure for passing Processing data to subprocessors.
 *
 * Separate structure is used to avoid passing too many parameters in
 * registers.
 */
struct SProcessQueryData
{
  TConnectionList *connectionlist;
  TConnectionListEntry *listentry;
  const THubCtrlProtocolHeader *reqhdr;
  const unsigned int req_size;
  
  uint8_t *replybuffer;
  unsigned int replybuffer_size;
  unsigned int *replybuffer_datasize;

  THubCtrlSubHeaderIdentificationHeader **subhdrtable;
  unsigned int subhdrcount;
};
//*****************************************************************************

//***************************************************************************

/**
 * HubCtrl structure. Contains HubCtrl specific data.
 */
typedef struct _hubctrl
{
  uint8_t *ap2ap_secret;          ///< Shared secret for AP2AP connections
  unsigned int ap2ap_secret_size; ///< AP2AP - Shared secret size

  uint8_t *APs_secret;          ///< Shared secret for AP Services
  unsigned int APs_secret_size; ///< Shared secret size for AP Services.
  unsigned int APs_reserved_pool_begin;
  unsigned int APs_reserved_pool_end;

  uint8_t *client_secret;          ///< Shared secret for Client connections
  unsigned int client_secret_size; ///< Client - Shared secret size


  unsigned int timestamp_difference_max; ///< Timestamp limit, +/- 30 sec
} THubCtrl;

//***************************************************************************

THubCtrl *hubctrlCreate();
int hubctrlInit(THubCtrl *hc);
void hubctrlDeinit(THubCtrl *hc);
void hubctrlDestroy(THubCtrl *hc);
const TProtocolEntry *hubctrlGetProtocolEntry(THubCtrl *);

void hubctrlSetAP2APSecret(THubCtrl *hc, const uint8_t *secret, const unsigned int secret_size);
void hubctrlSetAPServiceSecret(THubCtrl *hc, const uint8_t *secret, const unsigned int secret_size);
void hubctrlSetClientSecret(THubCtrl *hc, const uint8_t *secret, const unsigned int secret_size);

void hubctrlSetMaxTimestampDifference(THubCtrl *hc, const unsigned int timestamp_difference_max);

void hubctrlProtocolConstructHeader(THubCtrlProtocolHeader *hdr,
				    unsigned short int request,
				    unsigned short int flags);

void hubctrlDumpProtocolHeader(int l, const THubCtrlProtocolHeader *ph);


#endif //_HUBCTRL_H_





